﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vision.Common.Utility;

namespace Vision.Utilities.SetupTool.Task.Processors
{
    public class FolderUnitProcessor : IUnitProcessor
    {
        #region Implement IUnitProcessor
        public void Execute(UnitProcessorContext context)
        {
            if (context != null && context is FolderUnitProcessorContext)
            {
                DoExecute(context as FolderUnitProcessorContext);
            }
        }
        #endregion

        #region Helper Methods
        protected virtual void DoExecute(FolderUnitProcessorContext context)
        {
            var excludedFiles = (context.ExcludedFiles ?? new string[0]).ToArray();
            switch (context.Action)
            {
                case FileOperateAction.Delete:
                    FileSystemUtility.DeleteFolder(context.SourceFolder, true, excludedFiles);
                    break;
                case FileOperateAction.Copy:
                    FileSystemUtility.CopyFolder(context.SourceFolder, context.DestinationFolder, true);
                    break;
                case FileOperateAction.Clear:
                    FileSystemUtility.ClearSubFolders(context.SourceFolder, true, excludedFiles);
                    break;
                case FileOperateAction.None:
                default: break;
            }
        }
        #endregion
    }
}
